﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bll;
using Help;
using Model;

namespace Myproject.BSM.Ashx.PcBase
{
    /// <summary>
    /// FriendAdd 的摘要说明
    /// </summary>
    public class FriendAdd : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string FriendID = context.Request.Params["pc_base_friendEdit_friendID"].Trim();
            string FriendName = context.Request.Params["pc_base_friendEdit_name"].Trim();
            string FriendImgUrl = context.Request.Params["pc_base_friendEdit_imgurl"].Trim();
            string FriendRank = context.Request.Params["pc_base_friendEdit_frank"].Trim();
            string FriendUrl = context.Request.Params["pc_base_friendEdit_eurl"].Trim();
            string FriendFlag = context.Request.Params["pc_base_friendEdit_friendFlag"].Trim();
            if (FriendID == "0")
            {
                if (new FriendBLL().Add(FriendName, FriendImgUrl, Int32.Parse(FriendRank), FriendUrl, bool.Parse(FriendFlag)))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "新增友情链接成功！", "pc_base_FriendList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "新增友情链接失败！", "pc_base_FriendList", "", "", true, "", ""));
                }
            }
            else
            {
                FriendModel model = new FriendBLL().GetModel(Int32.Parse(FriendID));
                model.FriendName = FriendName;
                model.FriendImgUrl = FriendImgUrl;
                model.FriendRank = int.Parse(FriendRank);
                model.FriendUrl = FriendUrl;
                model.FriendFlag = bool.Parse(FriendFlag);
                if (new FriendBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改友情链接成功！", "pc_base_FriendList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改友情链接失败！", "pc_base_FriendList", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}